//#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <queue>
using namespace std;
char mg[1005][1005];
bool vis[1005][1005] = { 0 };
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, m;
	cin >> n >> m;
	for (int i = 1;i <= n;i++) {
		for (int j = 1;j <= m;j++) {
			cin >> mg[i][j];
		}
	}

	for (int i = 1;i <= n - 1;i++) {
		for (int j = 1;j <= m - 1;j++) {
			if (mg[i][j] == '.' && mg[i][j + 1] == '#' && mg[i + 1][j] == '#' && mg[i + 1][j + 1] == '#'||
				mg[i][j] == '#' && mg[i][j + 1] == '.' && mg[i + 1][j] == '#' && mg[i + 1][j + 1] == '#'||
				mg[i][j] == '#' && mg[i][j + 1] == '#' && mg[i + 1][j] == '.' && mg[i + 1][j + 1] == '#'||
				mg[i][j] == '#' && mg[i][j + 1] == '#' && mg[i + 1][j] == '#' && mg[i + 1][j + 1] == '.')
			{
				cout << "Bad placement." << endl;
				return 0;
			}
		}
	}
	queue<pair<int, int>>q;
	int dx[] = { 1,0,-1,0 };
	int dy[] = { 0,1,0,-1 };
	int count = 0;
	for (int i = 1;i <= n;i++) {
		for (int j = 1;j <= m;j++) {
			if (mg[i][j] == '#' && vis[i][j] == false)
			{
				count++;
				q.push({ i,j });
				vis[i][j] = true;
				while (!q.empty()) {
					int x = q.front().first;
					int y = q.front().second;
					q.pop();
					for (int k = 0;k < 4;k++) {
						int tx = x + dx[k];
						int ty = y + dy[k];
						if (vis[tx][ty] == true || mg[tx][ty] == '.')
							continue;
						if (tx<1 || ty<1 || tx>n || ty>m)
							continue;
						q.push({ tx,ty });
						vis[tx][ty] = true;
					}
				}
			}
		}
	}
	cout << "There are " << count << " ships." << endl;
	return 0;
}

//6 6
//.....#
//##...#
//##...#
//..#..#
//.....#
//######

//6 8
//.....###
//##.....#
//##.....#
//.......#
//#......#
//#..#...#